package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;
import ar.edu.caece.compiler.grammar.attributes.Attribute;
import ar.edu.caece.compiler.grammar.attributes.BooleanAttribute;
import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.Lambda;
import ar.edu.caece.compiler.model.LexicalAnalyzer;

public class LambdaFactory extends AbstractTokenVisitorFactory{

	private static LambdaFactory INSTANCE;
	
	public LambdaFactory(LexicalAnalyzer analizadorLexico) {
		super(analizadorLexico);
	}

	public LambdaFactory() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public TokenVisitor makeChainedVisitor(
			TokenVisitor siguiente) throws Exception {
		
		return makeVisitor();
	}

	@Override
	public TokenVisitor makeVisitor() throws Exception {
		
		return new TokenVisitor() {

			@Override
			public Recognizer defaultCase(TokenRecognizer llamador)
					throws Exception {
				backToken();
				Lambda lambda = Lambda.getInstance();
				
				lambda.addAttribute("tipo", new StringAttribute("NINGUNO"));
				lambda.addAttribute("es", new BooleanAttribute(false));
				lambda.addAttribute(Attribute.LISTA_PARAMETROS_SINTETIZADA, getAttribute(Attribute.LISTA_PARAMETROS_HEREDADA));
				lambda.addAttribute(Attribute.TABLA_SIMBOLOS_SINTETIZADA, getAttribute(Attribute.TABLA_SIMBOLOS_HEREDADA));
				lambda.addAttribute(Attribute.LISTA_VARIABLES_SINTETIZADA, getAttribute(Attribute.LISTA_VARIABLES_HEREDADA));
				lambda.addAttribute(Attribute.ARBOL_SINTETIZADO, getAttribute(Attribute.ARBOL_HEREDADO));
				return lambda;
			}
			
		};

	}

	public static LambdaFactory getInstance() {
		if(INSTANCE==null) INSTANCE = new LambdaFactory();
		return INSTANCE;
	}

}
